<?php
	$d = date('y/m/d');
    
    $meta_query = array(
		array(
			'key' => 'active_metadata',
			'value' => 'active',
			'compare' => '='),
		array(
			'key' => 'cp_rate_metadata',
			'value' => 50,
            'type' => 'NUMERIC',
			'compare' => '>='),
//        array(
//			'key' => 'expire_date_metadata',
//            'compare' => '>=',
//			'value' => $d,
//            'type' => 'DATE'
//			),
		array(
			'key' => 'store_coupon_metadata',
			'value' => $store_id,
			'compare' => '='));
   
    // Dont get duplicate cp in top rate
    $excerpt_not_in = array();    
    if(cpx_get_top_cp_rate($store_id) != null)
    {
        $top_rate_id = cpx_get_top_cp_rate($store_id);
        array_push($excerpt_not_in, $top_rate_id[0]);
    }
    // Dont get duplicate cp in un-popular
    $un_popular_cps = cpx_get_unpopular_coupons($store_id, $d);
    if(count($un_popular_cps) > 0)
    {
        foreach ($un_popular_cps as $p) {
            array_push($excerpt_not_in, (int)$p->ID);
        }
    }
    
	$args = array(
		'post_type' => 'coupon',
        'post__not_in'=> $excerpt_not_in,
		'post_status' => 'publish',
		'meta_query' => $meta_query,
		'orderby' => 'date',
		'order' => 'DESC',
		'posts_per_page' => $itemsToShow);
        
	$query = new WP_Query($args);
	if ($query->have_posts())
	{ ?>
        <div class="row-fluid boxf">
                        <div class="row-fluid header-coupon">
                            <div class="span12 code-coupon"><h2><?php echo $title;?></h2></div>
                        </div>
    <?php
		foreach ($query->posts as $v)
		{
            $cp_id = $v->ID;
            cpx_get_coupon_detail($cp_id, $v->comment_count);
        } ?>           
        </div>
    <?php
	}
?>
